home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 4
/
Apprentice-Release4.iso
/
Languages
/
PowerMacOberon 1.2
/
Source
/
Tools
/
Count.Mod
(
.txt
)
< prev
next >
Wrap
Oberon Text
|
1995-08-22
|
3KB
|
88 lines
Syntax10.Scn.Fnt
FoldElems
Syntax10.Scn.Fnt
(*-----------------------------------------------------
Counts lines, statements and characters in an Oberon-2 module
Count.Lines (^ | * | filename {filename})
Count.Statements (^ | * | filename {filename})
Count.Chars (^ | * | filename {filename})
-----------------------------------------------------*)
Syntax10i.Scn.Fnt
Syntax10b.Scn.Fnt
Documentation
MODULE Count;
IMPORT Oberon, Texts, TextFrames, Viewers, Out;
PROCEDURE Open(VAR t: Texts.Text; VAR s: Texts.Scanner);
VAR v: Viewers.Viewer; beg, end, time: LONGINT;
BEGIN
Texts.OpenScanner(s, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(s);
IF (s.class = Texts.Char) & (s.c = "^") THEN
Oberon.GetSelection(t, beg, end, time);
IF time >= 0 THEN
Texts.OpenScanner(s, t, beg); Texts.Scan(s)
END
END;
IF (s.class = Texts.Char) & (s.c = "*") THEN
v := Viewers.This(Oberon.Pointer.X, Oberon.Pointer.Y);
t := v.dsc.next(TextFrames.Frame).text
ELSE t := NIL
END Open;
PROCEDURE L(t: Texts.Text): LONGINT;
VAR r: Texts.Reader; ch: CHAR; lines: LONGINT;
BEGIN
Texts.OpenReader(r, t, 0); Texts.Read(r, ch); lines := 0;
WHILE ch # 0X DO
IF ch = 0DX THEN INC(lines) END;
Texts.Read(r, ch)
END;
RETURN lines
END L;
PROCEDURE Chars*;
VAR s: Texts.Scanner; chars: LONGINT; t: Texts.Text;
BEGIN
Open(t, s);
IF t # NIL THEN
Out.F("# chars$", t.len)
ELSE
WHILE s.class = Texts.Name DO
NEW(t); Texts.Open(t, s.s);
Out.String(s.s); Out.F(" # chars$", t.len);
Texts.Scan(s)
END
END Chars;
PROCEDURE Lines*;
VAR s: Texts.Scanner; t: Texts.Text;
BEGIN
Open(t, s);
IF t # NIL THEN
Out.F("# lines$", L(t))
ELSE
WHILE s.class = Texts.Name DO
NEW(t); Texts.Open(t, s.s);
Out.String(s.s); Out.F(" lines$", L(t));
Texts.Scan(s)
END
END Lines;
PROCEDURE Statements*;
VAR t: Texts.Text; s: Texts.Scanner; n: INTEGER; count, empty: BOOLEAN;
BEGIN
Open(t, s);
IF t = NIL THEN NEW(t); Texts.Open(t, s.s) END;
Texts.OpenScanner(s, t, 0); Texts.Scan(s); n := 0; count := FALSE;
WHILE ~ s.eot DO
IF (s.class = Texts.Char) & (s.c = ";") & count THEN
INC(n); empty := FALSE; Texts.Scan(s);
IF (s.class = Texts.Name) & (s.s = "END") THEN DEC(n) END
ELSIF (s.class = Texts.Name) & (s.s = "BEGIN") THEN
count := TRUE; empty := TRUE; Texts.Scan(s)
ELSIF (s.class = Texts.Name) & (s.s = "END") THEN
IF count & ~empty THEN INC(n) END;
empty := FALSE; Texts.Scan(s);
IF (s.class = Texts.Name) & (s.s # "END") THEN count := FALSE END
ELSE empty := FALSE; Texts.Scan(s)
END
END;
Out.F("# statements$", n)
END Statements;
END Count.